package com.yao.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.yao.bean.R;
import com.yao.exception.MyExtendOAuth2Exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class MyExtendOAuth2ExceptionSerializer extends StdSerializer<MyExtendOAuth2Exception> {

    private static final Logger log = LoggerFactory.getLogger(MyExtendOAuth2ExceptionSerializer.class);

    public MyExtendOAuth2ExceptionSerializer() {
        super(MyExtendOAuth2Exception.class);
    }

    @Override
    public void serialize(MyExtendOAuth2Exception e, JsonGenerator jGen, SerializerProvider provider) throws IOException {
        log.info("MyCustomOAuth2Exception返回格式序列化处理，MyExtendOAuth2ExceptionSerializer.class -> e={}", e);

        // 自定义返回格式内容


        jGen.writeObject(R.ok().data(e.getMyExtendMessage()).msg(e.getMessage()));
    }
}
